package abs.syn;

import java.util.LinkedList;

import setting.BioNLPSettings;

public class DependencyPath implements Cloneable {
	public LinkedList<Dependency> deps = new LinkedList<Dependency>();
	public LinkedList<Boolean> isLeftArgument = new LinkedList<Boolean>();
	public void insert(Dependency dep, boolean isLeft){
		deps.add(dep);
		isLeftArgument.add(isLeft);
	}
	public void removeLast(){
		deps.removeLast();
		isLeftArgument.removeLast();
	}
	@Override public Object clone(){
		DependencyPath  path = new DependencyPath();
		for (int i = 0; i < deps.size(); i++){
			path.deps.add(deps.get(i));
			path.isLeftArgument.add(isLeftArgument.get(i));
		}
		return path;
	}
	
	public String getFeatureString(){
		String p = "";
		for (int j = 0; j < deps.size(); j++){
			if (BioNLPSettings.getBooleanValue("USE_DEP_SIGN"))
				p += deps.get(j).name+(isLeftArgument.get(j)?"+":"-");
			else
				p += deps.get(j).name/*+(pp.isLeftArgument.get(j)?"+":"-")*/;
		}
		return p;
	}
	
	public String getFeatureString(boolean useDepSign){
		String p = "";
		for (int j = 0; j < deps.size(); j++){
			if (useDepSign)
				p += deps.get(j).name+(isLeftArgument.get(j)?"+":"-");
			else
				p += deps.get(j).name/*+(pp.isLeftArgument.get(j)?"+":"-")*/;
		}
		return p;
	}
	

	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("path:{");
		if (!deps.isEmpty()){
			sb.append((isLeftArgument.get(0)?deps.get(0).toString().replace(", ","*, "):deps.get(0).toString().replace(", ",", *")));
			for (int i = 1; i < deps.size(); i++){
				sb.append(" -> "+(isLeftArgument.get(i)?deps.get(i).toString().replace(", ","*, "):deps.get(i).toString().replace(", ",", *")));
			}
		}
		sb.append("}");
		return sb.toString();
	}
	public boolean contains(Dependency dep) {
		return deps.contains(dep);
	}
}
